package org.polaris.basic.service.impl;

import org.polaris.basic.mapper.BaseMapper;
import org.polaris.basic.query.BaseQuery;
import org.polaris.basic.service.IBaseService;
import org.polaris.basic.tool.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public T selectById(Serializable id) {
        return baseMapper.selectById(id);
    }

    @Override
    public T selectByName(String name) {
        return baseMapper.selectByName(name);
    }

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    public void deleteById(Serializable id) {
        baseMapper.deleteById(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        baseMapper.batchDelete(ids);
    }

    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public Long selectTotal(BaseQuery baseQuery) {
        return baseMapper.selectTotal(baseQuery);
    }

    @Override
    public PageResult paging(BaseQuery baseQuery) {
        Long total = selectTotal(baseQuery);
        if (total > 0){
            List<T> t = baseMapper.paging(baseQuery);
            return new PageResult(total,t);
        }
        return new PageResult<>();
    }
}
